#!/bin/sh
# This regression test is a part of SIPp.
# Over SCTP, the UAS sees the association end when the UAC is done (its
# SHUTDOWN reads as 0 bytes), rather than failing to read from it again
# and again, and ends once its calls are done.
. "`dirname "$0"`/../functions"; init

"`get_sipp`" -v | grep -q SCTP || skip "no SCTP"
perl -e 'use Socket; socket(S, PF_INET, SOCK_STREAM, 132) || exit 1' ||
    skip "no SCTP sockets"

sippfg -sn uas -t s1 -i 127.0.0.1 -p 28000 -m 3 -timeout 4 \
    >/dev/null 2>&1 &
uas=$!
sleep 0.5
sippfg -sn uac -t s1 -i 127.0.0.1 -p 28001 127.0.0.1:28000 \
    -m 3 -r 10 -timeout 4 >/dev/null 2>&1
uac=$?
wait $uas
status=$?

if test $uac -ne 0; then
    fail "the UAC exited with $uac"
elif test $status -ne 0; then
    fail "the UAS exited with $status, not done at the UAC's SHUTDOWN"
fi
ok
